//
//  HDPracticeViewController.m
//  HDecoration
//
//  Created by 曹群 on 15/8/13.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDPracticeViewController.h"
#import "HDMenuView.h"
#import "HDWaitingViewController.h"
#import "HDAppointViewController.h"
#import "HDNearbyViewController.h"

@interface HDPracticeViewController ()
@property(nonatomic,strong)HDMenuView *menu;
@property(nonatomic,strong)HDNearbyViewController *nearbyVC;
@property(nonatomic,strong)HDWaitingViewController *waitingVC;
@property(nonatomic,strong)HDAppointViewController *appointVC;
@property(nonatomic,strong)UIViewController *currentVC;
@end

@implementation HDPracticeViewController

- (void)initUI {
    self.view.backgroundColor = kContentViewColor;
    [self.view addSubview:self.menu];
}

- (void)selectMenuIndex:(int)index
{
    if (self.currentVC) {
        if (self.currentVC.view.tag!=100+index)
        {
            [self.currentVC.view removeFromSuperview];
        }
        else
        {
            return;
        }
    }
    switch (index) {
        case 0:     //附近
        {
            [self.view addSubview:self.nearbyVC.view];
            self.currentVC = self.nearbyVC;
            self.nearbyVC.orderType = self.orderType;
            break;
        }
        case 1:     //指定单
        {
            [self.view addSubview:self.appointVC.view];
            self.currentVC = self.appointVC;
            self.appointVC.orderType = self.orderType;
            break;
        }
        case 2:     //待上课
        {
            [self.view addSubview:self.waitingVC.view];
            self.waitingVC.orderType = self.orderType;
            self.currentVC = self.waitingVC;
            break;
        }
        default:
            break;
    }
    
}


- (void)testDataFunc
{
    self.menu.selectedIndex = 0;
}

-(void)setOrderType:(HDOrderType)orderType
{
    _orderType=orderType;
    self.nearbyVC.orderType=orderType;
}

#pragma mark - getters
- (HDMenuView *)menu
{
    if (!_menu) {
        _menu = [[HDMenuView alloc] initWithFrame:CGRectMake(0, 63, APPFRAME.size.width, 40) titleArray:@[@"附近",@"指定单",@"待上课"]];
        _menu.delegate = (id)self;
    }
    return _menu;
}

- (HDNearbyViewController *)nearbyVC
{
    if (!_nearbyVC) {
        _nearbyVC = [[HDNearbyViewController alloc] init];
        _nearbyVC.view.frame = CGRectMake(0, self.menu.bottom+7, APPFRAME.size.width, SCREENFRAME.size.height-64-self.menu.height-7);
        _nearbyVC.view.tag = 100;
        _nearbyVC.delegate = self;
    }
    return _nearbyVC;
}

- (HDWaitingViewController *)waitingVC
{
    if (!_waitingVC) {
        _waitingVC = [[HDWaitingViewController alloc] init];
        _waitingVC.view.frame = CGRectMake(0, self.menu.bottom+7, APPFRAME.size.width, SCREENFRAME.size.height-64-self.menu.height-7);
        _waitingVC.orderType = self.orderType;
        _waitingVC.view.tag = 102;
    }
    return _waitingVC;
}

- (HDAppointViewController *)appointVC
{
    if (!_appointVC) {
        _appointVC = [[HDAppointViewController alloc] init];
        _appointVC.view.frame = CGRectMake(0, self.menu.bottom, APPFRAME.size.width, SCREENFRAME.size.height-64-self.menu.height-7);
        _appointVC.view.tag = 101;
        _appointVC.orderType = self.orderType;
    }
    return _appointVC;
}

#pragma Viewcontroller appear & disappear

-(void)viewWillAppear:(BOOL)animated
{
    [self.currentVC viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [self.currentVC viewWillDisappear:animated];
}

-(void)viewDidAppear:(BOOL)animated
{
    [self.currentVC viewDidAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [self.currentVC viewDidDisappear:animated];
}


@end
